//
//  QZHomeVC.m
//  ZBarScan
//
//  Created by QF_iOS on 2017/5/17.
//  Copyright © 2017年 QF_iOS. All rights reserved.
//

#import "QZHomeVC.h"

#import "QZViewController.h"

#import "QZMeViewController.h"

#import "LoginViewController.h"//登录界面

#import "YKCheckController.h"


@interface QZHomeVC ()

@end

@implementation QZHomeVC
{
    UIButton *logBtn;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self judgeHaveInterNet];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blueColor];
    self.navigationController.navigationBar.barTintColor = kNavigationMainColor;
    self.title = @"首页";
    //状态栏和导航栏字体全变为白色,
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    UIImageView *bgImgView = [[UIImageView alloc] initWithFrame:self.view.frame];
    bgImgView.image = [UIImage  imageNamed:@"bgc.png"] ;
    [self.view addSubview:bgImgView];
    
    
    UIImageView *titleImgView = [[UIImageView alloc] initWithFrame:CGRectMake(_750scale(80), _750scale(300), _750scale(1181 / 2), _750scale(354 / 2))];
    titleImgView.image = [UIImage imageNamed:@"logo_search.png"];
    [bgImgView addSubview:titleImgView];
    UIButton *centerBtn =  [UIButton createBtnFrame:CGRectMake((kScreenWidth - 221) / 2, (kScreenheight - 221) / 2+ _750scale(40), 325 / 2, 325 /2) imageName:nil radius:325 /2 / 2 inSuperView:self.view];
    
    [centerBtn setBackgroundImage:[UIImage imageNamed:@"图层2.png"] forState:UIControlStateNormal];
    
    
    centerBtn.backgroundColor = [UIColor clearColor];
    [centerBtn addTarget:self action:@selector(presentScanVCAction) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *presentBtn =  [UIButton createBtnFrame:CGRectMake((kScreenWidth - 221) / 2, (kScreenheight - 221) / 2+ _750scale(40), 221, 221) imageName:nil radius:221 / 2 inSuperView:self.view];
    

    [presentBtn setImage:[UIImage imageNamed:@"色相_饱和度-1.png"] forState:UIControlStateNormal];
    
    presentBtn.backgroundColor = [UIColor clearColor];
    [presentBtn addTarget:self action:@selector(presentScanVCAction) forControlEvents:UIControlEventTouchUpInside];
    presentBtn.showsTouchWhenHighlighted = YES;
    centerBtn.center = presentBtn.center;

    
    //登录
    logBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    logBtn.frame = CGRectMake(0, 0, 130, 40);
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60, 5, 50, 35)];
    label.backgroundColor = kNavigationMainColor;
    label.text  = @"登录";
    label.textColor = [UIColor whiteColor];
    [logBtn addSubview:label];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(40 +60, 12, 35 /2, 40  /2)];
    imageView.image = [UIImage imageNamed:@"user_icon.png"];
    [logBtn addSubview:imageView];
    

    [logBtn addTarget:self action:@selector(meVCAction) forControlEvents:UIControlEventTouchUpInside];
    
    

    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:logBtn];
    
    self.navigationItem.rightBarButtonItem = item;
    
    
    
    // 查看结果界面
//    UIButton *checkBtn = [UIButton createBtnFrame:CGRectMake(100, 100, 100, 100) title:nil titleColor:nil titleFont:nil bgColor:[UIColor orangeColor] radius:3 inSuperView:self.view];
//    [checkBtn addTarget:self action:@selector(checkBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)judgeHaveInterNet {
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown: {
                break;
            }
            case AFNetworkReachabilityStatusNotReachable: {
                          [self showTextHUDWithStr:@"请求网络失败，请检查您的网络..."];
                
                
                NSLog(@"无网络");
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWWAN: {
                                break;
            }
            case AFNetworkReachabilityStatusReachableViaWiFi: {
                                
                break;
            }
        }
    }];
    
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    

}


- (void)presentScanVCAction {
    
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown: {
                break;
            }
            case AFNetworkReachabilityStatusNotReachable: {
                //                               [[UIViewController currentViewController] showSuccessHUDWithStr:@"网络好像有点问题"];
                //                [[UIViewController currentViewController] showTextHUDWithStr:@"网络好像有点问题"];
                
                
//                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"网络好像有点问题" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
//                [alert show];
                [self showTextHUDWithStr:@"请求网络失败，请检查您的网络..."];
                
                
                NSLog(@"无网络");
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWWAN: {
                [self presentViewController:[QZViewController new] animated:YES completion:^{
                    
                }];

                break;
            }
            case AFNetworkReachabilityStatusReachableViaWiFi: {
                [self presentViewController:[QZViewController new] animated:YES completion:^{
                    
                }];

                break;
            }
        }
    }];
    
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];

    //模态出来扫描界面
   
    
    
    
}
//我的界面
- (void)meVCAction {
    NSLog(@"跳转我的界面");
    [self.navigationController pushViewController:[LoginViewController new] animated:YES];
//    [self presentViewController:[LoginViewController   new] animated:YES completion:^{
//        
//    }];
//    
}

// 查看
- (void)checkBtnClick
{
    YKCheckController *checkVC = [[YKCheckController alloc] init];
    [self.navigationController pushViewController:checkVC animated:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
  
    AppDelegate *appdelegate = kAppDelegate;
    NSLog(@"%@" , appdelegate.publicProperty.loginModel.User_Type);
    if (appdelegate.publicProperty.loginModel) {
        logBtn.userInteractionEnabled = NO;
    }
    if (appdelegate.publicProperty.loginModel) {
        for (UIView *view in logBtn.subviews) {
            if ([[UIImageView class] isSubclassOfClass:view.class]) {
                [view removeFromSuperview];
            }
            if ([[UILabel class] isSubclassOfClass:view.class]) {
                UILabel *label =(UILabel *) view;
                label.text = appdelegate.publicProperty.loginModel.User_Name;
                label.frame = CGRectMake(0, 5, 120, 35);
                label.textAlignment = NSTextAlignmentRight;
            }
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
